package com.gaozhen.demo;

import java.util.Random;
import java.util.Scanner;

public class Test7 {
    public static void main(String[] args) {
        //双色球系统判断
        //6个红球，1个蓝球（红球1-33号，蓝球1-16号，6个红球要求不能重复。 返回一个整型数组）
        int[] userNumber = userInputNumber();
        int[] luckNumber = createLuckNumber();
        judge(luckNumber,userNumber);


    }
    public static void judge(int[] luckNumber,int[] userNumber){
        //判断是否中奖
        int redHitNumber = 0;
        int blueHitNumber = 0;
        //红球号码
        for (int i = 0; i < userNumber.length-1; i++) {
            for (int j = 0; j < luckNumber.length-1; j++) {
                if(userNumber[i] == luckNumber[j]){
                    redHitNumber++;
                    break;
                }
            }
        }
        //蓝球号码
        blueHitNumber = luckNumber[6] == userNumber[6] ? 1 : 0;

        System.out.println("中奖号码是：");
        printArray(luckNumber);
        System.out.println("您投注的号码是：");
        printArray(userNumber);
        System.out.println("您命中的红球个数："+redHitNumber);
        System.out.println("您是否命中蓝球："+(blueHitNumber == 1 ? "命中" : "未命中"));


        //判断中奖情况
        if(blueHitNumber == 1 && redHitNumber < 3){
            System.out.println("中奖5元");
        } else if (blueHitNumber == 1 && redHitNumber == 3
                || blueHitNumber == 0 && redHitNumber == 4){
                System.out.println("中奖10元");
        }else if (blueHitNumber == 1 && redHitNumber == 4
                || blueHitNumber == 0 && redHitNumber == 5){
            System.out.println("中奖200元");
        }else if (blueHitNumber == 1 && redHitNumber == 5){
            System.out.println("中奖3000元");
        }else if (blueHitNumber == 0 && redHitNumber == 6){
            System.out.println("中奖500万元");
        }else if (blueHitNumber == 1 && redHitNumber == 6){
            System.out.println("中奖1000万元超级大奖");
        }
    }
    public static void printArray(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "\t");
        }
        System.out.println();
    }
    public static int[] userInputNumber(){
        //定义一个数组存储7个号码
        int[] numbers =new int[7];
        Scanner src = new Scanner(System.in);
        for (int i = 0; i < numbers.length-1; i++) {
            System.out.println("请输入第"+(i+1)+"个红球号码。");
            int data = src.nextInt();
            numbers[i] = data;
        }
        System.out.println("请输入蓝球号码（1-16）：");
        numbers[6] = src.nextInt();
        return numbers;
    }

    public static int[] createLuckNumber(){
        //定义一个动态初始化数组，存储7个数组
        int[] numbers =new int[7];
        //遍历数组，为每个位置生成一个对应的号码（6个不重复的红球号码，范围1-33）
        Random r = new Random();
        for (int i = 0; i < numbers.length-1; i++) {
            while(true){
                int data = r.nextInt(33)+1; // 1-33
                boolean flag = true;
                //判断是否重复
                for (int j = 0; j < i; j++) {
                    if (numbers[j] == data){
                        flag = false;
                        break;
                    }
                }
                if (flag){
                    numbers[i] = data;
                    break;
                }
            }

        }
        //蓝球号码
        numbers[numbers.length-1] = r.nextInt(16)+1;
        for (int i = 0; i < numbers.length; i++) {
            System.out.print(numbers[i]+ " ");
        }
        System.out.println();
        return numbers;
    }
}
